package cn.edu.hhu.DAO.impl;

import cn.edu.hhu.Bean.AttendanceTask;
import cn.edu.hhu.DAO.AttendanceTaskDao;
import cn.edu.hhu.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * @anthor: lddd
 * @date: 2020/5/10 - 13:54
 * @description:
 **/
public class AttendanceTaskDaoImpl implements AttendanceTaskDao {
    JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
    /**
     * 根据课程号查询任务
     * @param cid
     * @return 任务列表
     */
    @Override
    public List<AttendanceTask> queryTaskByCId(long cid) {
        String sql = "SELECT * FROM tasklist WHERE cid = ?";
        List<AttendanceTask> query = template.query(sql, new BeanPropertyRowMapper<>(AttendanceTask.class), cid);
        return query;
    }
    /**
     * 根据任务号查询任务
     * @param tnum
     * @return 任务列表
     */
    @Override
    public AttendanceTask queryTaskByTnum(long tnum) {
        try {
            String sql = "SELECT * FROM tasklist WHERE tnum = ?";
            AttendanceTask attendanceTask = template.queryForObject(sql, new BeanPropertyRowMapper<>(AttendanceTask.class), tnum);
            return attendanceTask;
        } catch (Exception e) {
            return null;
        }
    }
}
